package org.jeecg.modules.fund.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.fund.entity.FundLibrary;
import org.jeecg.modules.fund.mapper.FundLibraryMapper;
import org.jeecg.modules.fund.service.IFundLibraryService;
import org.jeecg.modules.fund.service.IFundValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@Api(tags = "基金库")
@RequestMapping("/sys/fund/library")
@Slf4j
public class FundLibraryController {
    @Autowired
    private IFundValueService fundValueService;
    @Autowired
    private IFundLibraryService fundLibraryService;
    @Autowired
    private FundLibraryMapper fundLibraryMapper;
    /**
     * 更新估值
     */
    @RequestMapping(value = "/estimate", method = RequestMethod.GET)
    public void estimate() {
        fundValueService.batchUpdateLine60();
    }

    @RequestMapping(value = "/val", method = RequestMethod.GET)
    public void val() {
        fundValueService.batchUpdateVal(true);
    }

    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Result<FundLibrary> detail(@RequestParam(name = "id") String id) {
        FundLibrary library = fundLibraryService.getById(id);
        return Result.OK(library);
    }

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result<IPage<Map<String, Object>>> queryPageList(FundLibrary fundLibrary,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
                                                            HttpServletRequest req) {
        // 分页设置
        Page<FundLibrary> page = new Page<>(pageNo, pageSize);
        // 分页
        IPage<Map<String, Object>> pageList = fundLibraryMapper.selectPageVo(page, fundLibrary);
        return Result.OK(pageList);
    }

    @RequestMapping(value = "/addPage", method = RequestMethod.GET)
    public Result<IPage<Map<String, Object>>> queryAddPageList(FundLibrary fundLibrary,
                                                            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                            @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize,
                                                            HttpServletRequest req) {
        // 分页设置
        Page<FundLibrary> page = new Page<>(pageNo, pageSize);
        // 分页
        IPage<Map<String, Object>> pageList = fundLibraryMapper.selectAddPageVo(page, fundLibrary);
        return Result.OK(pageList);
    }
}
